package com.yunti.springboot.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunti.springboot.po.Device;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
* <p>
    * api请求记录表 Mapper 接口
    * </p>
*
* @author ytt
* @since 2022-03-27
*/
    @Repository
    public interface DeviceMapper extends BaseMapper<Device> {
    @Insert("insert into device (device_name,online,password,type,create_time,update_time)" +
            " values (#{device.deviceName}, #{device.online}, #{device.password}," +
            " #{device.type}, #{device.create_time}, #{device.update_time})")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    Integer insertOne(@Param("device") Device device);

    @Select("select t1.id,t1.device_name as deviceName,t1.online,t1.type,t1.create_time,t1.update_time from device t1 left join device_school t2 on t1.id = t2.device_id where t2.school_id = #{schoolId}")
    List<Map<String,String>> getDevices(Integer schoolId);
}
